package cn.qin.xhangapi.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.qin.xhangapi.pojo.LoginLog;
import cn.qin.xhangapi.service.LoginLogService;
import cn.qin.xhangapi.util.response.ResponseResult;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/api/loginLog")
@RestController
public class LoginLogController {
    @Resource
    private LoginLogService loginLogService;

    /**
     * 获取当前登录系统用户登录日志
     *
     * @author 多仔ヾ
     * @return cn.duozai.ct.utils.response.ResponseResult
     */
    @GetMapping("/currentSysUserLoginLog")
    public ResponseResult currentSysUserLoginLog(
            @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        // 查询列表数据
        QueryWrapper<LoginLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", StpUtil.getLoginIdAsLong());
        // 根据登录时间倒序排列
        queryWrapper.orderByDesc("login_time");
        Page<LoginLog> pageInfo = new Page<>(pageNo, pageSize);
        loginLogService.page(pageInfo,queryWrapper);

        return ResponseResult.success(pageInfo);
    }
}
